<!DOCTYPE html>
<html lang="en">
<head>
    <!--收费管理-> 5,账单-->
    <meta charset="UTF-8">
    <title>账单</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css"/>
    <script src="../js/jquery.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    <style>
        table{
            text-align: center;
        }
    </style>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-12">
            <h1  style="font-weight: bolder;text-shadow:5px 5px 5px burlywood ">首页>收费管理>账单——><span id="span1">未交账单</span></h1>
        </div>
    </div>

    <!-- 点击查询-->
    <div class="row">
        <div class="col-md-11">
            <button class="btn-primary" value="f" id="anniu" >切换到已交账单</button>
        </div>
        <div class="col-md-1" id="but123">

        </div>
    </div>
    <div class="row" style="overflow: scroll;height:800px;">
        <div  class="col-md-12">
            <table style="table-layout: fixed"  class="table table-hover table-striped table-bordered" id="tableone3">
                <tr style="position: sticky;top:0;z-index: 999;font-weight: bolder;font-size: larger">
                    <td>
                    是否完成
                    </td>
                    <td>编号</td>
                    <td>姓名</td>
                    <td>房间号</td>
                    <td>费用名称</td>
                    <td>单价</td>
                    <td>数量</td>
                    <td>费用</td>
                    <td>账单日</td>
                    <td>缴费状态</td>
                </tr>
            </table>
        </div>
    </div>
</div>
<!--(1)收费管理→抄表录入->录入数据模态框-->
<div   class="modal fade" id="addmyModal3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h1 class="modal-title" id="myModalLabel">结算</h1>
            </div>
            <div class="modal-body">
                <div class="form-group has-feedback">
                    <label>业主</label>
                    <span id="span" class="glyphicon glyphicon-yen"></span>
                    <input id="yezhu" readonly/>元
                </div>
                <div class="form-group has-feedback">
                    <label >应收金额</label>
                    <span class="glyphicon glyphicon-yen"></span>
                    <input id="ysje" readonly/>元
                </div>
                <div class="form-group has-feedback">
                    <label class="glyphicon glyphicon-certificate" >缴费人</label>
                    <input id="jfr"/>
                </div>
                <div class="form-group has-feedback">
                    <label class="glyphicon glyphicon-certificate" >缴费方式</label>
                    <select id="jffs">
                        <option>现金</option>
                        <option>微信</option>
                        <option>支付宝</option>
                        <option>云闪付</option>
                    </select>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="button02" type="button" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    //身份
    let user;
    //总金额
    let money = 0
    /**
     * 点击切换状态
     */
    $("#anniu").on("click",function(){
        let str =   $(this).html()
        if(str=="切换到已交账单"){
            $("#jszd").html("已缴费")
            $("#span1").html("已交账单")
            $("#anniu").val("g")
            $(this).html("切换到未交账单")
        }else{
            $("#jszd").html("结  算")
            $("#anniu").val("f")
            $("#span1").html("未交账单")
            $(this).html("切换到已交账单")
        };
         $("#tableone3 tr:not(:first)").remove()
        if(user!=-1){
            money=0;
            setadd1(user);
        }else {
            setadd();
        }
    });

    /**
     * 管理员加载加全部数据
     */
    function setadd(){
        let str = $("#anniu").val()
        console.log(str)
        $.ajax({
            url:"bianhuachaxu",
            type:"post",
            dataType:"json",
            data:{"setter":str},
            success:function (data){
                console.log(data)
                for(let obj of data){
                    add(obj)
                }
            }
        });
    }

    /**
     * 住户加载全部数据
     */
    function setadd1(aid){
        let str = $("#anniu").val()
        $.ajax({
            url:"bianhuachaxu1",
            type:"post",
            dataType:"json",
            data:{"setter":str,"aid":aid},
            success:function (data){
                for(let obj of data){
                   money= money+parseInt(obj.summoney)
                    add(obj)
                }
            }
        });
    }





    /**
     * 加载组件并赋值
     */
    function add(obj){
        let tr =  document.createElement("tr");
        let td0 =  document.createElement("td");
        let td1 =  document.createElement("td");
        td1.innerText=obj.D_id
        let td2 =  document.createElement("td");
        td2.innerText=obj.Hname
        let td3 =  document.createElement("td");
        td3.innerText=obj.vname+obj.ttname+obj.Uname+obj.honame
        let td4 =  document.createElement("td");
        td4.innerText=obj.S_Name
        let td5 =  document.createElement("td");
        td5.innerText=obj.S_money
        let td6 =  document.createElement("td");
        td6.innerText=obj.D_sum
        let td7 =  document.createElement("td");
        td7.innerText=obj.summoney
        let td8 =  document.createElement("td");
        td8.innerText= obj.D_billdate.year+"-"+obj.D_billdate.monthValue+"-"+obj.D_billdate.dayOfMonth
        let td9 = document.createElement("td");
        if(obj.D_settle=="f"){
            td9.innerText= "未缴费"
            $(td0).html("未完成")
        }else {
            td9.innerText="已缴费"
            $(td0).html("已完成")
        }
        $(td9).attr("name","shouji")
        $(td9).val(obj.D_id)
        $(tr).append(td0,td1,td2,td3,td4,td5,td6,td7,td8,td9)
        $("#tableone3").append(tr)
    }
    /**-------已完成
     * 全选全部确定或取消
     */
    $("#chok").on("click",function(){
        let coks = document.getElementsByName("chox");
        if(this.checked){
            for(let i  = 0;i<coks.length;i++){
                coks[i].checked=true;
            }
        }else{
            for(let i  = 0;i<coks.length;i++){
                coks[i].checked=false;
            }
        }
    });

    /**
     * 判断是否是业主
     */
    $.ajax({
        url:"iszhuhuzhangdan",
        type:"get",
        dataType:"json",
        success:function(data){
            if(data!=-1){
                user=data
                let bun = document.createElement("button");
                $(bun).attr("class","btn btn-primary glyphicon glyphicon-yen")
                $(bun).attr("id","jszd")
                bun.innerText="结 算"
                /**
                 * 住户自己结算
                 */
                $(bun).on("click",function(){
                    let biaoshi =$(bun).html()
                    console.log(biaoshi)
                    if(biaoshi=="已缴费"){
                        alert("此页面是已缴费记录，无须重复缴费")
                    }else {
                        if(window.confirm("总缴费为："+money+"元，是否确认缴费？")){
                            $.ajax({
                                url:"zhuhujiaofei",
                                type:"post",
                                dataType:"json",
                                data:{"aid":user},
                                success:function (data){
                                    if(data){
                                        alert("结算成功")
                                        window.location.reload()
                                    }else {
                                        alert("结算失败，请从新结算")
                                    }
                                }
                            });
                        }else {
                            alert("已取消支付")
                        }

                    }
                });
                $("#but123").append(bun)
                setadd1(data);
            }else {
               user=data
               setadd();
            }
        }
    });
</script>
</html>